using System;
using System.Linq;
using Coderoom.ScrumPlanner.Data.Repositories;
using Coderoom.ScrumPlanner.Domain;

namespace Coderoom.ScrumPlanner.Tests.FakeRepositories
{
	public sealed class FakeThemeRepository : ThemeRepository
	{
		private ThemeCollection _data;

		public FakeThemeRepository()
		{
			SetupFakeData();
		}

		public override ThemeCollection GetThemes(Guid projectId)
		{
			var returnData = _data.Where(theme => theme.ProjectId == projectId);

			var themes = new ThemeCollection();
			foreach (var theme in returnData)
				themes.Add(theme);

			return themes;
		}

		public override Theme GetTheme(Guid themeId)
		{
			return _data.Where(theme => theme.Id == themeId).SingleOrDefault();
		}

		public override void CreateTheme(Theme theme)
		{
			theme.Id = Guid.NewGuid();

			_data.Add(theme);
		}

		public override bool DeleteTheme(Guid themeId)
		{
			Theme theme;

			if ((theme = GetTheme(themeId)) != null)
				return _data.Remove(theme);

			return false;
		}

		private void SetupFakeData()
		{
			_data = new ThemeCollection();

			_data.Add(new Theme {Id = new Guid("21FA55C7-CCD5-48D7-B5A9-BB9FD3CE1582"), ProjectId = new Guid("D8185A6C-7145-4751-B149-27B03AB9E5B6"), Title = "Theme A"});
			_data.Add(new Theme {Id = new Guid("AEA523B9-DE70-4660-BD78-2741BFCCFCCA"), ProjectId = new Guid("D8185A6C-7145-4751-B149-27B03AB9E5B6"), Title = "Theme B"});
			_data.Add(new Theme {Id = new Guid("60C7DC18-164C-4BB6-88C4-76D020ADF6EA"), ProjectId = new Guid("CF4F74C1-CE66-4B06-8480-B34445906423"), Title = "Theme X"});

			foreach (var theme in _data)
				theme.Slug = Entity.CreateSlug(theme.Title);
		}
	}
}